package com.aaa.book_mall.dao.impl;

import com.aaa.book_mall.dao.OutDetailDao;
import com.aaa.book_mall.entity.OutDetail;
import com.aaa.book_mall.util.JDBCUtil;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Description: 出库详情表的接口实现类
 * @ClassName: OutDetailDaoImpl
 * @Author: fengyun
 * @Date: 2021/1/20 14:09
 * @Version: 1.0
 */
@Repository
public class OutDetailDaoImpl implements OutDetailDao {
    @Override
    public int insertOutDetail(OutDetail outDetail) {
        String sql="insert into t_outdetail values(null,?,?,?)";
        int i = JDBCUtil.update(sql, outDetail.getOut_number(),outDetail.getBookid(),outDetail.getBookcount());
        return 0;
    }

    @Override
    public List<OutDetail> queryLOD(String outnumber) {
        String sql="select bookid,bookcount from t_outdetail where out_outnumber=?";
        List<List> lists = JDBCUtil.queryList(sql, outnumber);
        ArrayList<OutDetail> outDetails = new ArrayList<>();
        if(lists.size()>0){
            for (List list : lists) {
                OutDetail outDetail = new OutDetail((Integer) list.get(0), (Integer) list.get(1));
                outDetails.add(outDetail);
            }
            return outDetails;
        }
        return null;
    }

    @Override
    public List<Map<String, Object>> showInfoBOUT(String outnumber) {
        String sql="SELECT tod.out_outnumber,tb.bookname,tb.price,tod.bookcount,tb.count,tb.publisher from t_outdetail tod inner JOIN t_book tb on tb.bookid=tod.bookid where tod.bookid in (select bookid from t_outdetail where out_outnumber=?) and tod.out_outnumber=?";
        List<Map<String, Object>> maps = JDBCUtil.queryListMap(sql, outnumber, outnumber);
        return maps;
    }
}
